<?php

/**
 * 广告位置数据获取
 * @author Ice iceinto@mallog.com.cn
 */
class AdModel extends BaseModel {

	private $_type = 'ad';

	/**
	 * 返回需要的公告图片信息
	 * @param Array $map 获取数据条件
	 * @param String $field 字段
	 * @param String $order 排序
	 * @param String $limit 分页
	 * @return Array 返回广告数组
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function getAd($map, $field = 'm_ad.*,m_ad_allot.*', $order = 'm_ad.id DESC', $limit = '') {
		$data = array();
		$data = $this->where($map)
		->field($field)
		->join('INNER JOIN m_ad_allot ON m_ad.id = m_ad_allot.id')
		->join('INNER JOIN m_ad_type ON m_ad.type = m_ad_type.id')
		->order($order)
		->limit($limit)
		->select();
		foreach ($data as $k => $v) {
			$data[$k]['image_url'] = $this->getManagedUrl($v['image'], $this->_type);
			//只有首页和商场滚动广告图，其他广告全是品牌广告
			$url = '';
			if($v['url']){
				$url =$v['url'];
			}else{
				if ($v['mid'] && (!$v['fid'] || !$v['bid'])) {
					$url = $this->getAdUrl($v['mid']);
				} else if ($v['mid'] && $v['fid'] && $v['bid']) {
					$url = $this->getAdUrl($v['mid'], $v['fid'], $v['bid']);
				}else {
					$url = "javascript:;";
				}
			}
			$data[$k]['ad_url'] = $url;
		}
		return $data;
	}
}

?>